package practise;

import java.io.PrintWriter;
import java.io.StringWriter;

import com.google.appengine.api.utils.SystemProperty;

public class Utils {		
	
	public static String getCloudSqlURL() throws RuntimeException {
		
		try {			
			if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) {
				Class.forName("com.mysql.jdbc.GoogleDriver");
				
				return "jdbc:google:mysql://ishaportalproject:cloudsqltest/cloudsqltest?user=root";
			}
			
			//dev environment						
			Class.forName("com.mysql.jdbc.Driver");
			String url = "jdbc:mysql://127.0.0.1:3306/cloudsqltest?user=root&password=admin"; 
			
			if (null != System.getProperty("junittesting")) 
				url = "jdbc:mysql://127.0.0.1:3306/cloudsqltesttest?user=root&password=admin";
			
			return url;
			
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		}
	}
	
	public static String getStackTraceAsString(Throwable e) {
		StringWriter sw = new StringWriter();
		e.printStackTrace(new PrintWriter(sw));
		
		return sw.toString();
	}			
}
